<?php
class MyLibrary_LangSelector extends Zend_Controller_Plugin_Abstract{
    public function preDispatch(Zend_Controller_Request_Abstract $request){
        $lang = $request->getParam('lang');
        if($lang != 'vi' && $lang != 'en')
            $request->setParam('lang', 'vi');
        $lang = $request->getParam('lang');
        if($lang == 'vi')
            $locale = 'vi_VN';
        else 
            $locale = 'en_US';
        
        $zl = new Zend_Locale();
        $zl->setLocale($locale);
        Zend_Registry::set('Zend_Locale', $zl);
        Zend_Registry::set('lang', $lang);
        $translate = new Zend_Translate('csv', APPLICATION_PATH. '/configs/lang/' .$lang. '.csv', $lang);
        Zend_Registry::set('Zend_Translate', $translate);
         
    }
    
    public static function lang()
    {
    	return Zend_Registry::get('lang');
    }
}